<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table>
		  <tr>
			 <td><img src="" /></td>
			 <td colSpan="3">购物简易计算器</td>
		  </tr>
		  <tr>
			 <td>第一个数</td>
			 <td colSpan="3">
				 <input type="text" id="num1Id" />
			 </td>
		  </tr>
		  <tr>
			 <td>第二个数</td>
			 <td colSpan="3">
				 <input type="text" id="num2Id" />
			 </td>
		  </tr>
		  <tr>
			 <td>
				  <input type="button" value=" + " onclick="cal('+')"/>
			 </td>
			 <td>
				 <input type="button" value=" - " onclick="cal('-')"/>
			 </td>
			 <td>
				 <input type="button" value=" * " onclick="cal('*')"/>
			 </td>
			 <td>
				 <input type="button" value=" / " onclick="div()"/>
			 </td>
		  </tr>
		  <tr>
			 <td>计算结果</td>
			 <td colSpan="3">
				 <input  type="text" id="resultId" />
			 </td>
		  </tr>
	  </table>
	  
	  <script type="text/javascript">
		  function cal(type) {
			  var num1 = document.getElementById('num1Id').value;
			  var num2 = document.getElementById('num2Id').value;
			  // '3+5'  '3*5'
			  //var result = eval(parseInt(num1) + type + parseInt(num2));
			  var result = eval(num1 + type + num2);
			  var inputResultObj = document.getElementById('resultId');
			  inputResultObj.value = result;
		  }
		  
		  //var num1 = document.getElementById('num1Id').value;
		  //var num2 = document.getElementById('num2Id').value;
		  function cal2(type) {
			  var num1 = document.getElementById('num1Id').value;
			  var num2 = document.getElementById('num2Id').value;
			  var result = 0;
			  switch (type) {
			  	case '+':
					result = parseInt(num1) + parseInt(num2);
			  		break;
				case '-':
					result = parseInt(num1) - parseInt(num2);
					break;
				case '*':
					result = parseInt(num1) * parseInt(num2);
					break;
			  	default:
			  		break;
			  }
			  var inputResultObj = document.getElementById('resultId');
			  inputResultObj.value = result;
		  }
		  
	  	  function add() {
			  //document内置对象：对应已经new出来，名字也是固定的
			  //var inputObj1 = document.getElementById('num1Id');
			  //var num1 = inputObj1.value;
			  var num1 = document.getElementById('num1Id').value;
			  var num2 = document.getElementById('num2Id').value;
			  var result = parseInt(num1) + parseInt(num2);
			  var inputResultObj = document.getElementById('resultId');
			  inputResultObj.value = result;
		  }
		  
		  function sub() {
			  var num1 = document.getElementById('num1Id').value;
			  var num2 = document.getElementById('num2Id').value;
			  var result = parseInt(num1) - parseInt(num2);
			  var inputResultObj = document.getElementById('resultId');
			  inputResultObj.value = result;
		  }
		  
		  function mul() {
			  var num1 = document.getElementById('num1Id').value;
			  var num2 = document.getElementById('num2Id').value;
			  var result = parseInt(num1) * parseInt(num2);
			  var inputResultObj = document.getElementById('resultId');
			  inputResultObj.value = result;
		  }
	  </script>
	</body>
</html>